home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2004 April / Gamestar_61_2004-04_dvdb.iso / DVDStar / Editace / hltp.exe / {app} / Applications / MilkShape 3D / JSSamples / Unweld.js < prev   
Text File  |  2003-05-30  |  1KB  |  32 lines

  1. //////////////////////////////////////////////////////////////////////////////
  2. // Unweld.js
  3. // Sample script for the msToolJS plugin. Unwelds all vertices in a model.
  4. // Before running this script, make sure 'Auto Smooth' is selected!
  5. // By Ulf ╓hlΘn
  6.  
  7. for(im=0; im<model.meshes.length; im++)
  8. {
  9.     var mesh = model.meshes[im];
  10.     var oldVx = null;
  11.     var newVx = null;
  12.     var oldVxCount = mesh.vertices.length; // Original vertex count
  13.  
  14.     write("Unwelding mesh " + mesh.name + " ... ");
  15.  
  16.     for(it=0; it<mesh.triangles.length; it++)
  17.     {
  18.         tri = mesh.triangles[it];
  19.         // For each triangle, add 3 new vertices and remap the triangle's vertex indices
  20.         for(i=0; i<3; i++)
  21.         {
  22.             oldVx = mesh.vertices[tri.vertexIndices[i]];
  23.             newVx = new Vertex(oldVx.vertex.x, oldVx.vertex.y, oldVx.vertex.z, oldVx.u, oldVx.v, oldVx.boneIndex, oldVx.flags);
  24.             tri.vertexIndices[i] = mesh.vertices.length-oldVxCount;
  25.             mesh.vertices.push(newVx);
  26.         }
  27.     }
  28.     
  29.     if(mesh.vertices.length>0)
  30.         mesh.vertices.erase(0, oldVxCount); // Delete old vertices
  31.     write("" + mesh.vertices.length + " vertices OK\n");
  32. }